/*
 * File: power_on_and_power_off_practice2.c
 *
 * Code generated for Simulink model 'power_on_and_power_off_practice2'.
 *
 * Model version                  : 1.11
 * Simulink Coder version         : 25.1 (R2025a) 21-Nov-2024
 * C/C++ source code generated on : Thu Jul 31 15:58:03 2025
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "power_on_and_power_off_practice2.h"
#include "rtwtypes.h"

/* Named constants for Chart: '<Root>/StartUpAndShutDown' */
#define power__IN_MoterDischargeTimeOut ((uint8_T)6U)
#define power_o_IN_MainRlyDiscntTimeOut ((uint8_T)4U)
#define power_o_IN_Motor_DisableTimeOut ((uint8_T)8U)
#define power_on_IN_DCDC_DisableTimeOut ((uint8_T)2U)
#define power_on_IN_Motor_EnableTimeOut ((uint8_T)5U)
#define power_on__IN_DCDC_EnableTimeOut ((uint8_T)2U)
#define power_on_a_IN_MainRlyCntTimeOut ((uint8_T)3U)
#define power_on_an_IN_PrechargeTimeOut ((uint8_T)8U)
#define power_on_and_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define power_on_and_IN_SelfcheckFailed ((uint8_T)2U)
#define power_on_and__IN_MoterDischarge ((uint8_T)5U)
#define power_on_and_p_IN_Motor_Disable ((uint8_T)7U)
#define power_on_and_po_IN_DCDC_Disable ((uint8_T)1U)
#define power_on_and_po_IN_Motor_Enable ((uint8_T)4U)
#define power_on_and_pow_IN_DCDC_Enable ((uint8_T)1U)
#define power_on_and_power_IN_Precharge ((uint8_T)7U)
#define power_on_and_power_IN_ReadyLamp ((uint8_T)9U)
#define power_on_and_power_IN_Selfcheck ((uint8_T)1U)
#define power_on_and_power__IN_Finished ((uint8_T)3U)
#define power_on_and_power__IN_PowerOff ((uint8_T)9U)
#define power_on_and_power__IN_Presleep ((uint8_T)1U)
#define power_on_and_power_o_IN_Initial ((uint8_T)3U)
#define power_on_and_power_o_IN_PowerOn ((uint8_T)6U)
#define power_on_and_power_o_IN_Standby ((uint8_T)3U)
#define power_on_and_power_of_IN_HV_OFF ((uint8_T)1U)
#define power_on_and_power_of_IN_LV_OFF ((uint8_T)4U)
#define power_on_and_power_off_IN_HV_ON ((uint8_T)2U)
#define power_on_and_power_off_IN_LV_ON ((uint8_T)5U)
#define power_on_and_power_off_IN_Sleep ((uint8_T)2U)

/* Block states (default storage) */
DW_power_on_and_power_off_pra_T power_on_and_power_off_pract_DW;

/* External inputs (root inport signals with default storage) */
ExtU_power_on_and_power_off_p_T power_on_and_power_off_practi_U;

/* External outputs (root outports fed by signals with default storage) */
ExtY_power_on_and_power_off_p_T power_on_and_power_off_practi_Y;

/* Real-time model */
static RT_MODEL_power_on_and_power_o_T power_on_and_power_off_pract_M_;
RT_MODEL_power_on_and_power_o_T *const power_on_and_power_off_pract_M =
  &power_on_and_power_off_pract_M_;

/* Forward declaration for local functions */
static void power_on_and_power_off_p_HV_OFF(void);
static void power_on_and_power_off_pr_HV_ON(void);

/* Function for Chart: '<Root>/StartUpAndShutDown' */
static void power_on_and_power_off_p_HV_OFF(void)
{
  switch (power_on_and_power_off_pract_DW.is_HV_OFF) {
   case power_on_and_po_IN_DCDC_Disable:
    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 9.0;

    /* Outport: '<Root>/STD_stDCDCEn' */
    power_on_and_power_off_practi_Y.STD_stDCDCEn = 0.0;

    /* Inport: '<Root>/DCDC_stWorkMode' incorporates:
     *  Constant: '<Root>/Constant5'
     */
    if (power_on_and_power_off_practi_U.DCDC_stWorkMode == 5.0) {
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_power__IN_PowerOff;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 10.0;

      /* Outport: '<Root>/STD_stHVPwrReq' */
      power_on_and_power_off_practi_Y.STD_stHVPwrReq = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
    } else if ((power_on_and_power_off_pract_DW.i > 3.0) &&
               (power_on_and_power_off_practi_U.DCDC_stWorkMode != 5.0)) {
      power_on_and_power_off_pract_DW.i = 0.0;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_IN_DCDC_DisableTimeOut;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 249.0;

      /* Outport: '<Root>/STD_stDCDCDisaTimeout' */
      power_on_and_power_off_practi_Y.STD_stDCDCDisaTimeout = 1.0;
    } else {
      power_on_and_power_off_pract_DW.i += 0.01;
    }

    /* End of Inport: '<Root>/DCDC_stWorkMode' */
    break;

   case power_on_IN_DCDC_DisableTimeOut:
    /* Outport: '<Root>/STD_stDCDCDisaTimeout' */
    power_on_and_power_off_practi_Y.STD_stDCDCDisaTimeout = 1.0;
    power_on_and_power_off_pract_DW.is_HV_OFF = power_on_and_power__IN_PowerOff;

    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 10.0;

    /* Outport: '<Root>/STD_stHVPwrReq' */
    power_on_and_power_off_practi_Y.STD_stHVPwrReq = 0.0;
    power_on_and_power_off_pract_DW.i = 0.0;
    break;

   case power_on_and_power__IN_Finished:
    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 12.0;

    /* Inport: '<Root>/VIS_stKeyOn' */
    if (power_on_and_power_off_practi_U.VIS_stKeyOn == 0.0) {
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_of_IN_LV_OFF;
      power_on_and_power_off_pract_DW.is_LV_OFF =
        power_on_and_power__IN_Presleep;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 13.0;

      /* Outport: '<Root>/STD_stSleepFlg' */
      power_on_and_power_off_practi_Y.STD_stSleepFlg = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
    } else if (power_on_and_power_off_practi_U.VIS_stKeyOn == 1.0) {
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_off_IN_LV_ON;
      power_on_and_power_off_pract_DW.is_LV_ON = power_on_and_power_IN_Selfcheck;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 1.0;
      power_on_and_power_off_pract_DW.i = 0.0;
    }
    break;

   case power_o_IN_MainRlyDiscntTimeOut:
    /* Outport: '<Root>/STD_stMainRlyDiscntTimeout' */
    power_on_and_power_off_practi_Y.STD_stMainRlyDiscntTimeout = 1.0;
    power_on_and_power_off_pract_DW.is_HV_OFF = power_on_and__IN_MoterDischarge;

    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 11.0;

    /* Outport: '<Root>/STD_stMotorDischgReq' */
    power_on_and_power_off_practi_Y.STD_stMotorDischgReq = 1.0;
    power_on_and_power_off_pract_DW.i = 0.0;
    break;

   case power_on_and__IN_MoterDischarge:
    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 11.0;

    /* Outport: '<Root>/STD_stMotorDischgReq' */
    power_on_and_power_off_practi_Y.STD_stMotorDischgReq = 1.0;

    /* Inport: '<Root>/MCU_uBusVlotage' incorporates:
     *  Constant: '<Root>/Constant7'
     */
    if (power_on_and_power_off_practi_U.MCU_uBusVlotage < 60.0) {
      power_on_and_power_off_pract_DW.i = 0.0;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_power__IN_Finished;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 12.0;
    } else if ((power_on_and_power_off_pract_DW.i > 5.0) &&
               (power_on_and_power_off_practi_U.MCU_uBusVlotage >= 60.0)) {
      power_on_and_power_off_pract_DW.i = 0.0;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power__IN_MoterDischargeTimeOut;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 247.0;

      /* Outport: '<Root>/STD_stMotorDischgFailed' */
      power_on_and_power_off_practi_Y.STD_stMotorDischgFailed = 1.0;
    } else {
      power_on_and_power_off_pract_DW.i += 0.01;
    }

    /* End of Inport: '<Root>/MCU_uBusVlotage' */
    break;

   case power__IN_MoterDischargeTimeOut:
    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 247.0;

    /* Outport: '<Root>/STD_stMotorDischgFailed' */
    power_on_and_power_off_practi_Y.STD_stMotorDischgFailed = 1.0;

    /* Inport: '<Root>/VIS_stKeyOn' */
    if (power_on_and_power_off_practi_U.VIS_stKeyOn == 0.0) {
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_of_IN_LV_OFF;
      power_on_and_power_off_pract_DW.is_LV_OFF =
        power_on_and_power__IN_Presleep;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 13.0;

      /* Outport: '<Root>/STD_stSleepFlg' */
      power_on_and_power_off_practi_Y.STD_stSleepFlg = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
    } else if (power_on_and_power_off_practi_U.VIS_stKeyOn == 1.0) {
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_off_IN_LV_ON;
      power_on_and_power_off_pract_DW.is_LV_ON = power_on_and_power_IN_Selfcheck;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 1.0;
      power_on_and_power_off_pract_DW.i = 0.0;
    }
    break;

   case power_on_and_p_IN_Motor_Disable:
    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 8.0;

    /* Outport: '<Root>/STD_stReadyLamp' */
    power_on_and_power_off_practi_Y.STD_stReadyLamp = 0.0;

    /* Outport: '<Root>/STD_stMototEn' */
    power_on_and_power_off_practi_Y.STD_stMototEn = 0.0;

    /* Inport: '<Root>/MCU_stMotWorkMode' incorporates:
     *  Constant: '<Root>/Constant4'
     */
    if (power_on_and_power_off_practi_U.MCU_stMotWorkMode == 2.0) {
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_po_IN_DCDC_Disable;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 9.0;

      /* Outport: '<Root>/STD_stDCDCEn' */
      power_on_and_power_off_practi_Y.STD_stDCDCEn = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
    } else if ((power_on_and_power_off_pract_DW.i > 5.0) &&
               (power_on_and_power_off_practi_U.MCU_stMotWorkMode != 2.0)) {
      power_on_and_power_off_pract_DW.i = 0.0;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_o_IN_Motor_DisableTimeOut;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 250.0;

      /* Outport: '<Root>/STD_stMotorDisaTimeout' */
      power_on_and_power_off_practi_Y.STD_stMotorDisaTimeout = 1.0;
    } else {
      power_on_and_power_off_pract_DW.i += 0.01;
    }

    /* End of Inport: '<Root>/MCU_stMotWorkMode' */
    break;

   case power_o_IN_Motor_DisableTimeOut:
    /* Outport: '<Root>/STD_stMotorDisaTimeout' */
    power_on_and_power_off_practi_Y.STD_stMotorDisaTimeout = 1.0;
    power_on_and_power_off_pract_DW.is_HV_OFF = power_on_and_po_IN_DCDC_Disable;

    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 9.0;

    /* Outport: '<Root>/STD_stDCDCEn' */
    power_on_and_power_off_practi_Y.STD_stDCDCEn = 0.0;
    power_on_and_power_off_pract_DW.i = 0.0;
    break;

   default:
    /* Outport: '<Root>/STD_STATE' */
    /* case IN_PowerOff: */
    power_on_and_power_off_practi_Y.STD_STATE = 10.0;

    /* Outport: '<Root>/STD_stHVPwrReq' */
    power_on_and_power_off_practi_Y.STD_stHVPwrReq = 0.0;

    /* Inport: '<Root>/BMS_stMainRly' incorporates:
     *  Constant: '<Root>/Constant6'
     */
    if (power_on_and_power_off_practi_U.BMS_stMainRly == 0.0) {
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and__IN_MoterDischarge;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 11.0;

      /* Outport: '<Root>/STD_stMotorDischgReq' */
      power_on_and_power_off_practi_Y.STD_stMotorDischgReq = 1.0;
      power_on_and_power_off_pract_DW.i = 0.0;
    } else if ((power_on_and_power_off_pract_DW.i > 5.0) &&
               (power_on_and_power_off_practi_U.BMS_stMainRly == 1.0)) {
      power_on_and_power_off_pract_DW.i = 0.0;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_o_IN_MainRlyDiscntTimeOut;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 248.0;

      /* Outport: '<Root>/STD_stMainRlyDiscntTimeout' */
      power_on_and_power_off_practi_Y.STD_stMainRlyDiscntTimeout = 1.0;
    } else {
      power_on_and_power_off_pract_DW.i += 0.01;
    }

    /* End of Inport: '<Root>/BMS_stMainRly' */
    break;
  }
}

/* Function for Chart: '<Root>/StartUpAndShutDown' */
static void power_on_and_power_off_pr_HV_ON(void)
{
  /* Inport: '<Root>/VIS_stKeyOn' incorporates:
   *  Inport: '<Root>/FlT_stSysFltLvl'
   *  Inport: '<Root>/GSM_vVehSpd'
   *  Inport: '<Root>/OBC_stConnectCC'
   */
  if (((power_on_and_power_off_practi_U.VIS_stKeyOn == 0.0) &&
       (power_on_and_power_off_practi_U.GSM_vVehSpd < 3.0)) ||
      (power_on_and_power_off_practi_U.FlT_stSysFltLvl == 3.0) ||
      (power_on_and_power_off_practi_U.OBC_stConnectCC == 1.0)) {
    power_on_and_power_off_pract_DW.is_HV_ON = power_on_and_IN_NO_ACTIVE_CHILD;
    power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
      power_on_and_power_of_IN_HV_OFF;
    power_on_and_power_off_pract_DW.is_HV_OFF = power_on_and_p_IN_Motor_Disable;

    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 8.0;

    /* Outport: '<Root>/STD_stReadyLamp' */
    power_on_and_power_off_practi_Y.STD_stReadyLamp = 0.0;

    /* Outport: '<Root>/STD_stMototEn' */
    power_on_and_power_off_practi_Y.STD_stMototEn = 0.0;
    power_on_and_power_off_pract_DW.i = 0.0;
  } else {
    switch (power_on_and_power_off_pract_DW.is_HV_ON) {
     case power_on_and_pow_IN_DCDC_Enable:
      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 5.0;

      /* Outport: '<Root>/STD_stDCDCEn' */
      power_on_and_power_off_practi_Y.STD_stDCDCEn = 1.0;

      /* Inport: '<Root>/DCDC_stWorkMode' incorporates:
       *  Constant: '<Root>/Constant2'
       */
      if (power_on_and_power_off_practi_U.DCDC_stWorkMode == 3.0) {
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on_and_po_IN_Motor_Enable;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 6.0;

        /* Outport: '<Root>/STD_stMototEn' */
        power_on_and_power_off_practi_Y.STD_stMototEn = 1.0;
        power_on_and_power_off_pract_DW.i = 0.0;
      } else if ((power_on_and_power_off_pract_DW.i > 3.0) &&
                 (power_on_and_power_off_practi_U.DCDC_stWorkMode != 3.0)) {
        power_on_and_power_off_pract_DW.i = 0.0;
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on__IN_DCDC_EnableTimeOut;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 252.0;

        /* Outport: '<Root>/STD_stDCDCEnTimeout' */
        power_on_and_power_off_practi_Y.STD_stDCDCEnTimeout = 1.0;
      } else {
        power_on_and_power_off_pract_DW.i += 0.01;
      }

      /* End of Inport: '<Root>/DCDC_stWorkMode' */
      break;

     case power_on__IN_DCDC_EnableTimeOut:
      /* Outport: '<Root>/STD_stDCDCEnTimeout' */
      power_on_and_power_off_practi_Y.STD_stDCDCEnTimeout = 1.0;
      power_on_and_power_off_pract_DW.is_HV_ON = power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_of_IN_HV_OFF;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_p_IN_Motor_Disable;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 8.0;

      /* Outport: '<Root>/STD_stReadyLamp' */
      power_on_and_power_off_practi_Y.STD_stReadyLamp = 0.0;

      /* Outport: '<Root>/STD_stMototEn' */
      power_on_and_power_off_practi_Y.STD_stMototEn = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
      break;

     case power_on_a_IN_MainRlyCntTimeOut:
      /* Outport: '<Root>/STD_stMainRlyCntTimeout' */
      power_on_and_power_off_practi_Y.STD_stMainRlyCntTimeout = 1.0;
      power_on_and_power_off_pract_DW.is_HV_ON = power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_of_IN_HV_OFF;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_p_IN_Motor_Disable;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 8.0;

      /* Outport: '<Root>/STD_stReadyLamp' */
      power_on_and_power_off_practi_Y.STD_stReadyLamp = 0.0;

      /* Outport: '<Root>/STD_stMototEn' */
      power_on_and_power_off_practi_Y.STD_stMototEn = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
      break;

     case power_on_and_po_IN_Motor_Enable:
      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 6.0;

      /* Outport: '<Root>/STD_stMototEn' */
      power_on_and_power_off_practi_Y.STD_stMototEn = 1.0;

      /* Inport: '<Root>/MCU_stMotWorkMode' incorporates:
       *  Constant: '<Root>/Constant3'
       */
      if (power_on_and_power_off_practi_U.MCU_stMotWorkMode == 4.0) {
        power_on_and_power_off_pract_DW.i = 0.0;
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on_and_power_IN_ReadyLamp;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 7.0;

        /* Outport: '<Root>/STD_stReadyLamp' */
        power_on_and_power_off_practi_Y.STD_stReadyLamp = 1.0;
      } else if ((power_on_and_power_off_pract_DW.i > 5.0) &&
                 (power_on_and_power_off_practi_U.MCU_stMotWorkMode != 4.0)) {
        power_on_and_power_off_pract_DW.i = 0.0;
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on_IN_Motor_EnableTimeOut;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 251.0;

        /* Outport: '<Root>/STD_stMotorEnTimeout' */
        power_on_and_power_off_practi_Y.STD_stMotorEnTimeout = 1.0;
      } else {
        power_on_and_power_off_pract_DW.i += 0.01;
      }

      /* End of Inport: '<Root>/MCU_stMotWorkMode' */
      break;

     case power_on_IN_Motor_EnableTimeOut:
      /* Outport: '<Root>/STD_stMotorEnTimeout' */
      power_on_and_power_off_practi_Y.STD_stMotorEnTimeout = 1.0;
      power_on_and_power_off_pract_DW.is_HV_ON = power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_of_IN_HV_OFF;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_p_IN_Motor_Disable;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 8.0;

      /* Outport: '<Root>/STD_stReadyLamp' */
      power_on_and_power_off_practi_Y.STD_stReadyLamp = 0.0;

      /* Outport: '<Root>/STD_stMototEn' */
      power_on_and_power_off_practi_Y.STD_stMototEn = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
      break;

     case power_on_and_power_o_IN_PowerOn:
      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 4.0;

      /* Outport: '<Root>/STD_stHVPwrReq' */
      power_on_and_power_off_practi_Y.STD_stHVPwrReq = 1.0;

      /* Inport: '<Root>/BMS_stMainRly' incorporates:
       *  Constant: '<Root>/Constant1'
       */
      if (power_on_and_power_off_practi_U.BMS_stMainRly == 1.0) {
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on_and_pow_IN_DCDC_Enable;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 5.0;

        /* Outport: '<Root>/STD_stDCDCEn' */
        power_on_and_power_off_practi_Y.STD_stDCDCEn = 1.0;
        power_on_and_power_off_pract_DW.i = 0.0;
      } else if ((power_on_and_power_off_pract_DW.i > 3.0) &&
                 (power_on_and_power_off_practi_U.BMS_stMainRly == 0.0)) {
        power_on_and_power_off_pract_DW.i = 0.0;
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on_a_IN_MainRlyCntTimeOut;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 253.0;

        /* Outport: '<Root>/STD_stMainRlyCntTimeout' */
        power_on_and_power_off_practi_Y.STD_stMainRlyCntTimeout = 1.0;
      } else {
        power_on_and_power_off_pract_DW.i += 0.01;
      }

      /* End of Inport: '<Root>/BMS_stMainRly' */
      break;

     case power_on_and_power_IN_Precharge:
      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 3.0;

      /* Inport: '<Root>/BMS_stPrechg' incorporates:
       *  Constant: '<Root>/Constant'
       */
      if (power_on_and_power_off_practi_U.BMS_stPrechg == 2.0) {
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on_and_power_o_IN_PowerOn;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 4.0;

        /* Outport: '<Root>/STD_stHVPwrReq' */
        power_on_and_power_off_practi_Y.STD_stHVPwrReq = 1.0;
        power_on_and_power_off_pract_DW.i = 0.0;
      } else if ((power_on_and_power_off_pract_DW.i > 2.0) &&
                 (power_on_and_power_off_practi_U.BMS_stPrechg != 2.0)) {
        power_on_and_power_off_pract_DW.i = 0.0;
        power_on_and_power_off_pract_DW.is_HV_ON =
          power_on_an_IN_PrechargeTimeOut;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 254.0;

        /* Outport: '<Root>/STD_stPrechgTimeout' */
        power_on_and_power_off_practi_Y.STD_stPrechgTimeout = 1.0;
      } else {
        power_on_and_power_off_pract_DW.i += 0.01;
      }

      /* End of Inport: '<Root>/BMS_stPrechg' */
      break;

     case power_on_an_IN_PrechargeTimeOut:
      /* Outport: '<Root>/STD_stPrechgTimeout' */
      power_on_and_power_off_practi_Y.STD_stPrechgTimeout = 1.0;
      power_on_and_power_off_pract_DW.is_HV_ON = power_on_and_IN_NO_ACTIVE_CHILD;
      power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
        power_on_and_power_of_IN_HV_OFF;
      power_on_and_power_off_pract_DW.is_HV_OFF =
        power_on_and_p_IN_Motor_Disable;

      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 8.0;

      /* Outport: '<Root>/STD_stReadyLamp' */
      power_on_and_power_off_practi_Y.STD_stReadyLamp = 0.0;

      /* Outport: '<Root>/STD_stMototEn' */
      power_on_and_power_off_practi_Y.STD_stMototEn = 0.0;
      power_on_and_power_off_pract_DW.i = 0.0;
      break;

     default:
      /* Outport: '<Root>/STD_STATE' */
      /* case IN_ReadyLamp: */
      power_on_and_power_off_practi_Y.STD_STATE = 7.0;

      /* Outport: '<Root>/STD_stReadyLamp' */
      power_on_and_power_off_practi_Y.STD_stReadyLamp = 1.0;
      break;
    }
  }

  /* End of Inport: '<Root>/VIS_stKeyOn' */
}

/* Model step function */
void power_on_and_power_off_practice2_step(void)
{
  /* Chart: '<Root>/StartUpAndShutDown' incorporates:
   *  Constant: '<Root>/Constant8'
   *  Inport: '<Root>/FlT_stSysFltLvl'
   *  Inport: '<Root>/OBC_stConnectCC'
   *  Inport: '<Root>/VIS_stBrk'
   *  Inport: '<Root>/VIS_stGearTarget'
   *  Inport: '<Root>/VIS_stKeyOn'
   *  Inport: '<Root>/VIS_stKeyStart'
   *  Inport: '<Root>/VIS_stVCUSefChk'
   */
  if (power_on_and_power_off_pract_DW.is_active_c3_power_on_and_power == 0) {
    power_on_and_power_off_pract_DW.is_active_c3_power_on_and_power = 1U;
    power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
      power_on_and_power_o_IN_Initial;

    /* Outport: '<Root>/STD_STATE' */
    power_on_and_power_off_practi_Y.STD_STATE = 0.0;
  } else {
    switch (power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr) {
     case power_on_and_power_of_IN_HV_OFF:
      power_on_and_power_off_p_HV_OFF();
      break;

     case power_on_and_power_off_IN_HV_ON:
      power_on_and_power_off_pr_HV_ON();
      break;

     case power_on_and_power_o_IN_Initial:
      /* Outport: '<Root>/STD_STATE' */
      power_on_and_power_off_practi_Y.STD_STATE = 0.0;
      if (power_on_and_power_off_practi_U.VIS_stKeyOn == 1.0) {
        power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
          power_on_and_power_off_IN_LV_ON;
        power_on_and_power_off_pract_DW.is_LV_ON =
          power_on_and_power_IN_Selfcheck;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 1.0;
        power_on_and_power_off_pract_DW.i = 0.0;
      }
      break;

     case power_on_and_power_of_IN_LV_OFF:
      if (power_on_and_power_off_practi_U.VIS_stKeyOn == 1.0) {
        power_on_and_power_off_pract_DW.is_LV_OFF =
          power_on_and_IN_NO_ACTIVE_CHILD;
        power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
          power_on_and_power_off_IN_LV_ON;
        power_on_and_power_off_pract_DW.is_LV_ON =
          power_on_and_power_IN_Selfcheck;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 1.0;
        power_on_and_power_off_pract_DW.i = 0.0;
      } else if (power_on_and_power_off_pract_DW.is_LV_OFF ==
                 power_on_and_power__IN_Presleep) {
        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 13.0;

        /* Outport: '<Root>/STD_stSleepFlg' */
        power_on_and_power_off_practi_Y.STD_stSleepFlg = 0.0;
        if (power_on_and_power_off_pract_DW.i > 5.0) {
          power_on_and_power_off_pract_DW.i = 0.0;
          power_on_and_power_off_pract_DW.is_LV_OFF =
            power_on_and_power_off_IN_Sleep;

          /* Outport: '<Root>/STD_STATE' */
          power_on_and_power_off_practi_Y.STD_STATE = 14.0;

          /* Outport: '<Root>/STD_stSleepFlg' */
          power_on_and_power_off_practi_Y.STD_stSleepFlg = 1.0;
        } else {
          power_on_and_power_off_pract_DW.i += 0.01;
        }
      } else {
        /* Outport: '<Root>/STD_STATE' */
        /* case IN_Sleep: */
        power_on_and_power_off_practi_Y.STD_STATE = 14.0;

        /* Outport: '<Root>/STD_stSleepFlg' */
        power_on_and_power_off_practi_Y.STD_stSleepFlg = 1.0;
      }
      break;

     default:
      /* case IN_LV_ON: */
      if (power_on_and_power_off_practi_U.VIS_stKeyOn == 0.0) {
        power_on_and_power_off_pract_DW.is_LV_ON =
          power_on_and_IN_NO_ACTIVE_CHILD;
        power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
          power_on_and_power_of_IN_LV_OFF;
        power_on_and_power_off_pract_DW.is_LV_OFF =
          power_on_and_power__IN_Presleep;

        /* Outport: '<Root>/STD_STATE' */
        power_on_and_power_off_practi_Y.STD_STATE = 13.0;

        /* Outport: '<Root>/STD_stSleepFlg' */
        power_on_and_power_off_practi_Y.STD_stSleepFlg = 0.0;
        power_on_and_power_off_pract_DW.i = 0.0;
      } else {
        switch (power_on_and_power_off_pract_DW.is_LV_ON) {
         case power_on_and_power_IN_Selfcheck:
          /* Outport: '<Root>/STD_STATE' */
          power_on_and_power_off_practi_Y.STD_STATE = 1.0;
          if (power_on_and_power_off_practi_U.VIS_stVCUSefChk == 1.0) {
            power_on_and_power_off_pract_DW.i = 0.0;
            power_on_and_power_off_pract_DW.is_LV_ON =
              power_on_and_power_o_IN_Standby;

            /* Outport: '<Root>/STD_STATE' */
            power_on_and_power_off_practi_Y.STD_STATE = 2.0;
          } else if ((power_on_and_power_off_pract_DW.i > 20.0) &&
                     (power_on_and_power_off_practi_U.VIS_stVCUSefChk == 0.0)) {
            power_on_and_power_off_pract_DW.i = 0.0;
            power_on_and_power_off_pract_DW.is_LV_ON =
              power_on_and_IN_SelfcheckFailed;

            /* Outport: '<Root>/STD_STATE' */
            power_on_and_power_off_practi_Y.STD_STATE = 255.0;
          } else {
            power_on_and_power_off_pract_DW.i++;
          }
          break;

         case power_on_and_IN_SelfcheckFailed:
          /* Outport: '<Root>/STD_STATE' */
          power_on_and_power_off_practi_Y.STD_STATE = 255.0;
          if (power_on_and_power_off_practi_U.VIS_stVCUSefChk == 1.0) {
            power_on_and_power_off_pract_DW.is_LV_ON =
              power_on_and_power_o_IN_Standby;

            /* Outport: '<Root>/STD_STATE' */
            power_on_and_power_off_practi_Y.STD_STATE = 2.0;
          }
          break;

         default:
          /* Outport: '<Root>/STD_STATE' */
          /* case IN_Standby: */
          power_on_and_power_off_practi_Y.STD_STATE = 2.0;
          if (power_on_and_power_off_practi_U.VIS_stVCUSefChk == 0.0) {
            power_on_and_power_off_pract_DW.is_LV_ON =
              power_on_and_IN_SelfcheckFailed;

            /* Outport: '<Root>/STD_STATE' */
            power_on_and_power_off_practi_Y.STD_STATE = 255.0;
          } else if ((power_on_and_power_off_practi_U.FlT_stSysFltLvl < 3.0) &&
                     ((power_on_and_power_off_practi_U.VIS_stGearTarget == 2.0) ||
                      (power_on_and_power_off_practi_U.VIS_stGearTarget == 0.0))
                     && (power_on_and_power_off_practi_U.VIS_stBrk == 1.0) &&
                     (power_on_and_power_off_practi_U.OBC_stConnectCC == 0.0) &&
                     (power_on_and_power_off_practi_U.VIS_stKeyStart == 1.0)) {
            power_on_and_power_off_pract_DW.is_LV_ON =
              power_on_and_IN_NO_ACTIVE_CHILD;
            power_on_and_power_off_pract_DW.is_c3_power_on_and_power_off_pr =
              power_on_and_power_off_IN_HV_ON;
            power_on_and_power_off_pract_DW.is_HV_ON =
              power_on_and_power_IN_Precharge;

            /* Outport: '<Root>/STD_STATE' */
            power_on_and_power_off_practi_Y.STD_STATE = 3.0;
            power_on_and_power_off_pract_DW.i = 0.0;
          }
          break;
        }
      }
      break;
    }
  }

  /* End of Chart: '<Root>/StartUpAndShutDown' */
}

/* Model initialize function */
void power_on_and_power_off_practice2_initialize(void)
{
  /* (no initialization code required) */
}

/* Model terminate function */
void power_on_and_power_off_practice2_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
